<template>
  <view class="list-item">
    <!-- 左侧区域 -->
    <view class="goods-item-left">
      <!-- 复选框 -->
      <radio v-if="isShow" value="r2" :checked="goods.goods_state" color="#be0108" @click="readioHandle(goods)" />
      <image class="goods-img" :src="goods.goods_small_logo || defaultPic" mode="widthFix"></image>
    </view>
    <!-- 右侧区域 -->
    <view class="goods-item-right">
      <!-- 商品名字 -->
      <view class="goods-name">{{goods.goods_name}}</view>
      <!-- 商品价格 -->
      <view class="goods-info">
        <!-- 加减数字输入框 -->
        <view class="goods-price">￥{{ goods.goods_price | tofixed }}</view>
        <uni-number-box v-if="isNum" :min="0" :value="goods.goods_count" :max="9" @change="changNum"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name:"my-goods",
    props: {
      // 数据
      goods: {
        type: Object,
        default: {}
      },
      // 是否展示复选框
      isShow: {
        type: Boolean,
        default: false
      },
      isNum: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        // 默认图片
        defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
      };
    },
    // 过滤器
    filters: {
      tofixed(num) {
        // 保留两位小数
        return Number(num).toFixed(2)
      }
    },
    methods: {
      // 点击复选框是否选中
      readioHandle(goods) {
        this.$emit('changeRedio', {
          goods_id: this.goods.goods_id,
          goods_state: !this.goods.goods_state
        })
      },
      // 点击传递val数量值
      changNum(val) {
        // console.log(val);
        this.$emit('changeNum', {
          goods_id: this.goods.goods_id,
          goods_count: val - 0 // 减0是保证goods_count是Number
        })
      }
      
    }
    
  }
</script>

<style lang="scss" scoped>
.list-item{
  box-sizing: border-box;
  padding: 10px 5px;
  border-bottom: 1px solid #ccc;
  display: flex;
  .goods-item-left{
    margin-right: 5px;
    display: flex;
    align-items: center;
    .goods-img{
      width: 100px;
      height: 100px;
      display: block;
    }
  }
  .goods-item-right{
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-between;
    .goods-name{
      font-size: 13px;
    }
    .goods-price{
      font-size: 16px;
      color: #c00000;
    }
  }
}
.goods-info{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
</style>